﻿Imports System.Data.OleDb


Public Class AddPicture
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Sub Uploadbtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Uploadbtn.Click
       



        'TxtDate.Text = DateAndTime.Now.ToString()
        TxtDate.Text = Date.Now.ToString()



        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("MacrgraphyConnectionString").ConnectionString)
        Dim sql = "insert into Images(Images,Img_Description,Date_added,Cat_Id,UserName,Location,Camera) values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd = New OleDbCommand(sql, conn)
        If (Pic_Upload.HasFile) Then
            'Pic_Upload.SaveAs(Request.MapPath("images") & "/" & Catdropdown.SelectedItem.Text & "/" & Pic_Upload.FileName)

            Dim picLocationOnServerHardDisk = Request.MapPath("images") & "/" & Catdropdown.SelectedItem.Text & "/" & Pic_Upload.FileName
            Pic_Upload.SaveAs(picLocationOnServerHardDisk)
        End If


        conn.Open()
        cmd.Parameters.AddWithValue("@f1", "images/" & Catdropdown.SelectedItem.Text & "/" & Pic_Upload.FileName)
        cmd.Parameters.AddWithValue("@f2", TxtDescription.Text)
        cmd.Parameters.AddWithValue("@f3", TxtDate.Text)

        cmd.Parameters.AddWithValue("@f4", Catdropdown.SelectedValue)
        cmd.Parameters.AddWithValue("@f5", User.Identity.Name)
        'cmd.Parameters.AddWithValue("@f5", TxtUserName.Text)
        cmd.Parameters.AddWithValue("@f6", TxtLoc.Text)
        cmd.Parameters.AddWithValue("@f7", TxtCam.Text)

        cmd.ExecuteNonQuery()
        conn.Close()


        Response.Redirect("Default.aspx")
    End Sub
End Class